#ifndef __CLASS_MAIN_MANGER_H__
#define __CLASS_MAIN_MANGER_H__

#include <Arduino.h>
#include <Protothread.hpp>
#include <asyncHTTPrequest.h>
#include <WiFiUdp.h>
#include <NTPClient.h>

class MainManger : public Protothread
{
public:
    struct TimeOnEntry
    {
        int start;
        int end;
    };
    typedef std::vector<TimeOnEntry> TimeOnList;

private:

    int32_t _wifiFaile;
    // ExpiryTimer _ex_timer;

    TimeOnList _timeOns;
    bool _light;
    asyncHTTPrequest request;
    WiFiUDP ntpUDP;

    NTPClient _ntp;
public:
    MainManger(/* args */);
    ~MainManger();

    void init();

    bool begin();

    void loop();

    virtual bool Run();

    // void ntpSyncEvent(NTPSyncEvent_t event);
    void requestCB(void* optParm, asyncHTTPrequest* request, int readyState);

    time_t getEpochTime();
private:
    bool connect();
    void loadTimeCfg();
    bool checkLight();
    void pushMessage(String msg);
};

#endif //!__CLASS_WIFI_MANGER_H__